/**
 * 
 */
package org.swing.utility.jai.canvas;

import java.awt.Component;
import java.awt.Event;

/**
 * @author lqnhu
 *
 */
public class Delay extends Thread {
	long timeout; /* Timeout Interval */
	Event event; /* The Target Event */
	Component item; /* The Target Component */

	/** Accept a Event and Post it after Timeout */
	public Delay(long _timeout, Event _event, Component _item) {
		timeout = _timeout;
		event = _event;
		item = _item;
		start();
	}

	/** Post a KEY_PRESS Event after Timeout */
	public Delay(long _timeout, int key, Component _item) {
		this(_timeout,
				new Event(_item, 0, Event.KEY_PRESS, 0, 0, key, 0, _item),
				_item);
	}

	/** The Thread Run Implement */
	public void run() {
		try {
			sleep(timeout);
		} catch (InterruptedException e) {
			item.handleEvent(event);
		}
    }
}
